<template>
	<view>
		<checkbox-group @change="checkboxChange">
			<view>
				<scroll-view class="mycss-scroll-view-H" scroll-x="true">
					<view class="mycss-flex-start">
						<view class="uni-ma-3">
							<u-button :type="showFirstCol?'primary':'warning'" size="mini"
								@click="showFirstColF()">隐藏首列</u-button>
						</view>
						<view class="uni-ma-3">
							<u-button type="primary" size="mini" @click="doLeaveWords()">留言</u-button>
						</view>
						<view class="uni-ma-3">
							<u-button type="warning" size="mini" @click="alertSet()">提醒设置</u-button>
						</view>
						<view class="uni-ma-3 mycss-flex-start">
							<u-button text="<上周" size="mini" type="primary" @click="changeWeek('preWeek')"></u-button>
							<u-button text="本周" size="mini" type="primary" @click="changeWeek('nowWeek')"></u-button>
							<u-button text="下周>" size="mini" type="primary" @click="changeWeek('nextWeek')"></u-button>
						</view>
						<view class="uni-ma-3">
							<u-button type="primary" @click="showCalendar=true" size="mini">日期选择</u-button>
						</view>
						<view class="uni-ma-3">
							<u-button :type="chartShow?'warning':'primary'" @click="showChart()"
								size="mini">{{chartShow?'隐藏统计图':'显示统计图'}}</u-button>
						</view>
					</view>
				</scroll-view>
				<slot name="toolbar"></slot>
				<!-- 			<view class="charts-box">
				<StatisticalPie :tableData="tableData" v-if="false"></StatisticalPie>
			</view> -->
				<view class="uni-container">
					<view class="mycss-flex-start">
						<view style="width:140px" v-if="showFirstCol">
							<uni-table border stripe>
								<uni-tr>
									<uni-th align="center">
										<view>
											时间段｜日期
										</view>
									</uni-th>
								</uni-tr>
								<uni-tr v-for="item in tdata.morningTimeList" :key="item.endTime">
									<uni-td align="center">
										<view>
											{{ item.startTime }}-{{ item.endTime }}
										</view>
									</uni-td>
								</uni-tr>
								<uni-tr>
									<uni-td align="center">
										<view class="noback">
											下班
										</view>
									</uni-td>
								</uni-tr>
								<uni-tr v-for="item in tdata.afternoonTimeList" :key="item.endTime">
									<uni-td align="center">
										<view>
											{{ item.startTime }}-{{ item.endTime }}
										</view>
									</uni-td>
								</uni-tr>
								<uni-tr>
									<uni-td align="center">
										<view class="noback">
											下班
										</view>
									</uni-td>
								</uni-tr>
								<uni-tr v-for="item in tdata.nightTimeList" :key="item.endTime">
									<uni-td align="center">
										<view @click="toggle('bottom')">
											{{ item.startTime }}-{{ item.endTime }}
										</view>
									</uni-td>
								</uni-tr>
								<uni-tr>
									<uni-td align="center" rowspan="4">
										<view class="noback">
											报告
										</view>
									</uni-td>
								</uni-tr>
								<uni-tr>
									<uni-td align="center">
										<view class="noback">
											&nbsp;
										</view>
									</uni-td>
								</uni-tr>
								<uni-tr>
									<uni-td align="center">
										<view class="noback">
											&nbsp;
										</view>
									</uni-td>
								</uni-tr>
								<uni-tr>
									<uni-td align="center">
										<view class="noback">
											&nbsp;
										</view>
									</uni-td>
								</uni-tr>
								<uni-tr>
									<uni-td align="center">
										<view class="noback">
											&nbsp;
										</view>
									</uni-td>
								</uni-tr>
							</uni-table>
						</view>
						<uni-table :loading="loading" border stripe emptyText="暂无更多数据">
							<uni-tr>
								<uni-th align="center" v-for="(item,index) in tableData" :key="index">
									<text :class="item.workDate==formatDate(new Date(), 'yyyy-MM-dd')?'uni-primary':''"
										style="white-space: nowrap;">
										{{item.workDate}}({{getChineseFromIndex(index)}})
									</text>
								</uni-th>
							</uni-tr>
							<uni-tr v-for="item in tdata.morningTimeList" :key="item.endTime">
								<uni-td align="center" v-for="(n,i) in [0,1,2,3,4,5,6]" :key="i">
									<view class="mycss-flex-start" :class="getItemForClass(n,item,'c')">
										<checkbox :value="getCheckBoxName(n,item)" v-if="getItem(n,item)?true:false"
											color="#FFCC33" style="transform:scale(0.7)"
											:checked="clickItems.includes(getCheckBoxName(n,item))" />
										<view :class="getItemForClass(n,item)"
											@click="toggle('bottom',n,item,getItem(n,item)?'edit':'new')">
											<view class="mycontent">
												{{getItem(n,item)?getItem(n,item).content:"&nbsp;"}}
											</view>
											<uni-badge class="uni-badge-left-margin bfloat"
												v-if="getItem(n,item)?getItem(n,item).state==1:false" text="完成"
												:customStyle="{background: '#5fd652'}" />
										</view>
									</view>
								</uni-td>
							</uni-tr>
							<uni-tr>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
							</uni-tr>
							<uni-tr v-for="item in tdata.afternoonTimeList" :key="item.endTime">
								<uni-td align="center" v-for="(n,i) in [0,1,2,3,4,5,6]" :key="i">
									<view class="mycss-flex-start" :class="getItemForClass(n,item,'c')">
										<checkbox :value="getCheckBoxName(n,item)" color="#FFCC33"
											:checked="clickItems.includes(getCheckBoxName(n,item))"
											v-if="getItem(n,item)?true:false" style="transform:scale(0.7)" />
										<view :class="getItemForClass(n,item)"
											@click="toggle('bottom',n,item,getItem(n,item)?'edit':'new')">
											<view class="mycontent">
												{{getItem(n,item)?getItem(n,item).content:"&nbsp;"}}
											</view>
											<uni-badge class="uni-badge-left-margin bfloat"
												v-if="getItem(n,item)?getItem(n,item).state==1:false" text="完成"
												:customStyle="{background: '#5fd652'}" />
										</view>
									</view>
								</uni-td>
							</uni-tr>
							<uni-tr>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
							</uni-tr>
							<uni-tr v-for="item in tdata.nightTimeList" :key="item.endTime">
								<uni-td align="center" v-for="(n,i) in [0,1,2,3,4,5,6]" :key="i">
									<view class="mycss-flex-start" :class="getItemForClass(n,item,'c')">
										<checkbox :value="getCheckBoxName(n,item)" color="#FFCC33"
											:checked="clickItems.includes(getCheckBoxName(n,item))"
											v-if="getItem(n,item)?true:false" style="transform:scale(0.7)" />
										<view :class="getItemForClass(n,item)"
											@click="toggle('bottom',n,item,getItem(n,item)?'edit':'new')">
											<view class="mycontent">
												{{getItem(n,item)?getItem(n,item).content:"&nbsp;"}}
											</view>
											<uni-badge class="uni-badge-left-margin bfloat"
												v-if="getItem(n,item)?getItem(n,item).state==1:false" text="完成"
												type="primary" :customStyle="{background: '#5fd652'}" />
										</view>
									</view>
								</uni-td>
							</uni-tr>
							<uni-tr>
								<uni-td align="center" v-for="(item,index) in [0,1,2,3,4,5,6]" :key="index">
									<view class="noback" @click="goReport(0,index)">
										日报【{{getChineseFromIndex(item)}}】
									</view>
								</uni-td>
							</uni-tr>
							<uni-tr>
								<uni-td align="center">
									<view class="noback" @click="goReport(1)">
										周报
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
							</uni-tr>
							<uni-tr>
								<uni-td align="center">
									<view class="noback" @click="goReport(2)">
										月报
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
							</uni-tr>
							<uni-tr>
								<uni-td align="center">
									<view class="noback" @click="goReport(3)">
										季报
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
							</uni-tr>
							<uni-tr>
								<uni-td align="center">
									<view class="noback" @click="goReport(4)">
										年报
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
								<uni-td align="center">
									<view class="noback">
										&nbsp;
									</view>
								</uni-td>
							</uni-tr>
						</uni-table>
					</view>
				</view>
				<view>
					<uni-popup ref="popup" background-color="#fff">
						<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
							<scroll-view scroll-y="true" class="mycss-max-height85">
								<uni-row>
									<uni-col>
										<view class="mycss-flex-around mycss-title-bg">
											<view class="uni-ma-5">
												<text>{{openTitle}}</text>
											</view>
										</view>
									</uni-col>
								</uni-row>
								<uni-card title="日期" v-if="isEdit==false&&isMulti==false">
									<view class="mycss-flex-start-clumncenter-warp">
										<button
											:type="item.workDate==clickDate||selectDayList.includes(item.workDate)?'primary':'default'"
											:disabled="item.workDate==clickDate?true:false" size="mini"
											:plain="item.workDate==clickDate||selectDayList.includes(item.workDate)?false:true"
											class="uni-ma-2" style="padding:0px 10px;" v-for="(item,index) in tableData"
											:key="index"
											@click="dayClick(item)">{{item.workDate.substring(5)}}&nbsp;{{getChineseFromIndex(index)}}</button>
									</view>
								</uni-card>
								<uni-card title="上午" v-if="!isEdit">
									<view class="mycss-flex-start-clumncenter-warp">
										<button :type="getButtonType(todayUseTime,item,selectTimeList)"
											:disabled="todayUseTime.includes(item.startTime+'-'+item.endTime)?true:false"
											size="mini"
											:plain="todayUseTime.includes(item.startTime+'-'+item.endTime)||selectTimeList.includes(item.startTime+'-'+item.endTime)?false:true"
											class="uni-ma-2" style="padding:0px 10px;"
											v-for="(item,index) in tdata.morningTimeList" :key="index"
											@click="timeClick(item)">{{item.startTime}}-{{item.endTime}}</button>
									</view>
								</uni-card>
								<uni-card title="下午" v-if="!isEdit">
									<view class="mycss-flex-start-clumncenter-warp">
										<button :type="getButtonType(todayUseTime,item,selectTimeList)"
											:disabled="todayUseTime.includes(item.startTime+'-'+item.endTime)?true:false"
											size="mini"
											:plain="todayUseTime.includes(item.startTime+'-'+item.endTime)||selectTimeList.includes(item.startTime+'-'+item.endTime)?false:true"
											class="uni-ma-2" style="padding:0px 10px;"
											v-for="(item,index) in tdata.afternoonTimeList" :key="index"
											@click="timeClick(item)">{{item.startTime}}-{{item.endTime}}</button>
									</view>
								</uni-card>
								<uni-card title="晚上" v-if="!isEdit">
									<view class="mycss-flex-start-clumncenter-warp">
										<button :type="getButtonType(todayUseTime,item,selectTimeList)"
											:disabled="todayUseTime.includes(item.startTime+'-'+item.endTime)?true:false"
											size="mini"
											:plain="todayUseTime.includes(item.startTime+'-'+item.endTime)||selectTimeList.includes(item.startTime+'-'+item.endTime)?false:true"
											class="uni-ma-2" style="padding:0px 10px;"
											v-for="(item,index) in tdata.nightTimeList" :key="index"
											@click="timeClick(item)">{{item.startTime}}-{{item.endTime}}</button>
									</view>
								</uni-card>
								<uni-card title="时间段" v-if="isEdit&&isMulti==false">
									<view class="mycss-flex-start-clumncenter-warp">
										<button type="primary"
											disabled>{{editobj.startTime+"-"+editobj.endTime}}</button>
									</view>
								</uni-card>
								<uni-card title="类型(必须)">
									<view class="mycss-flex-start-clumncenter-warp">
										<u-radio-group v-model="typeDefault">
											<u-radio :customStyle="{margin: '5px'}" v-for="(item, index) in typeList"
												:key="index" :label="item.name" :name="item.id"
												@change="radioTypeChange">
											</u-radio>
										</u-radio-group>
										<!-- <u-switch v-model="ywShow" @change="switchChange"></u-switch> -->
									</view>
									<view v-if="projectShow">
										<u-tag text="没有可用的工程列表" type="warning" v-if="projectList.length==0">
										</u-tag>
										<u-radio-group v-model="projectClickData">
											<u-radio :customStyle="{margin: '5px'}" v-for="(item, index) in projectList"
												:key="index" :label="item.name" :name="item.id"
												@change="radioTypeChangeProject">
											</u-radio>
										</u-radio-group>
									</view>
									<view v-if="ywShow">
										<u-radio-group v-model="updownClickData">
											<u-radio :customStyle="{margin: '5px'}" v-for="(item, index) in updownList"
												:key="index" :label="item.label" :name="item.id"
												@change="radioTypeChangeUpdown">
											</u-radio>
										</u-radio-group>
										<uni-easyinput class="uni-mt-5" v-model="inputSearchYw" suffixIcon="search"
											placeholder="输入业务名称" @iconClick="searchYw"></uni-easyinput>
										<u-line color="#2979ff"></u-line>
										<u-radio-group v-model="displayAddrClickData">
											<u-radio :customStyle="{margin: '5px'}"
												v-for="(item, index) in dispAddrList" :key="index" :label="item.name"
												:name="item.id+'_'+item.name" @change="radioTypeChangeYwlist">
											</u-radio>
										</u-radio-group>
									</view>
								</uni-card>
								<uni-card title="标题(必须)">
									<view class="mycss-flex-start-clumncenter-warp">
										<u-tag :text="item.name" :bgColor="item.color" closable
											@close="deleteTag(item,'personal-title')" v-for="(item,index) in titleTags"
											:key="index" @click="clickTag(item.name,'title')">
										</u-tag>
									</view>
									<view class="mycss-flex-start-clumncenter-warp">
										<uni-icons type="compose" size="30" @click="openColorPick"
											:color="clickColor"></uni-icons>
										<uni-easyinput class="uni-mt-5" v-model="inputTitleText" suffixIcon="plus"
											placeholder="输入标题" @iconClick="addTag('personal-title')"></uni-easyinput>
									</view>
								</uni-card>
								<uni-card title="计划内容">
									<view class="mycss-flex-start-clumncenter-warp">
										<u-tag :text="item.name" :bgColor="item.color" closable
											@close="deleteTag(item,'personal-content')"
											v-for="(item,index) in contentTags" @click="clickTag(item.name,'content')"
											:key="index">
										</u-tag>
									</view>
									<view class="mycss-flex-start-clumncenter-warp">
										<uni-easyinput class="uni-mt-5" v-model="inputContentText" suffixIcon="plus"
											placeholder="输入内容" @iconClick="addTag('personal-content')"></uni-easyinput>
									</view>
								</uni-card>
							</scroll-view>
							<uni-row>
								<uni-col>
									<view class="mycss-flex-end">
										<view class="uni-ma-3">
											<button type="primary" size="mini" @click="planSave()">保存</button>
										</view>
										<view class="uni-ma-3">
											<button type="warn" size="mini" @click="planClose">关闭</button>
										</view>
									</view>
								</uni-col>
							</uni-row>
						</view>
					</uni-popup>
				</view>
			</view>
		</checkbox-group>
		<TColorPicker ref="colorPicker" @confirm="confirmColor"></TColorPicker>
		<u-datetime-picker :show="showCalendar" v-model="selectDate" mode="date" closeOnClickOverlay
			@confirm="confirmDate" @cancel="cancelDate"></u-datetime-picker>
		<u-toast ref="myuToast"></u-toast>
		<uni-fab v-if="clickItems.length>0" ref="myfab" :pattern="fab.pattern" :content="fab.content"
			:horizontal="fab.horizontal" :vertical="fab.vertical" :direction="fab.direction" @trigger="triggerfab" />
	</view>
</template>
<script setup>
	import {
		ref,
		onMounted,
		reactive,
		inject,
		watch
	} from 'vue';
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app";
	import {
		formatDate,
		parseDate
	} from '@/utils/dateUtil.js' //日期格式化
	import TColorPicker from '@/components/t-color-picker/t-color-picker.vue'
	import StatisticalPie from '@/pages/personal-plan/components/statistical-pie/statistical-pie.vue'
	import fab from '@/pages/personal-plan/components/fab.js'
	import tdata from '@/pages/personal-plan/components/tdata.js'
	const utils = inject("$utils");
	const http = inject("$http");
	const pinia = inject("$pinia")
	const props = defineProps({
		senditem: {
			type: Object,
			default: null
		}
	})
	watch(() => props.senditem, (val, preVal) => {
		console.log(val, "-----------");
		params.value.userId = val.id;
		findData();
	});
	//onMounted
	onMounted(() => {
		console.log(popup.value); // Proxy {…}
		console.log(colorPicker.value);
		console.log(myuToast.value);
		console.log(myfab.value);
	});
	//onLoad方法
	onLoad(() => {
		changeWeek('nowWeek')
	});
	const pageLoading = ref(true)
	const showFirstCol = ref(true);
	//是不是多项编辑
	const isMulti = ref(false);
	//点击选中的项目
	const clickItems = reactive([]);
	//是否显示浮动菜单
	const showFab = ref(false);
	//浮动菜单ref
	const myfab = ref();
	//是否是编辑
	const isEdit = ref(false);
	//editobj
	let editobj = {};
	//弹出框title
	const openTitle = ref("个人计划新增")
	//业务输入框
	const inputSearchYw = ref("");
	const myuToast = ref();
	const selectDate = ref(Date.now())
	const chartShow = ref(false);
	const showCalendar = ref(false);
	const popupDialog = ref();
	const params = ref({
		page: 1,
		size: 7
	});
	const color = ref({
		r: 255,
		g: 0,
		b: 0,
		a: 0.6
	});
	const popButtons = ['复制', '删除'];
	const clickColor = ref("#8e8e8e"); //确认后的颜色
	const colorPicker = ref();
	const tableData = reactive([]);
	const total = ref(0);
	const loading = ref(false);
	const popup = ref();
	const tmap = new Map();
	//选择的时间list
	const selectTimeList = reactive([]);
	const selectDayList = reactive([]);
	const todayUseTime = reactive([]);
	const clickDate = ref();

	//上下游list
	const updownList = reactive([]);
	//类型list前台写死
	const typeList = reactive([{
		"id": 0,
		"name": "日常事务"
	}, {
		"id": 1,
		"name": "项目事务"
	}, {
		"id": 3,
		"name": "额外事务"
	}, {
		"id": 4,
		"name": "请假"
	}, {
		"id": 5,
		"name": "业务专属"
	}]);
	const typeDefault = ref(0);
	//地点list
	const addrList = reactive([]);
	//用来显示的地址列表
	const dispAddrList = reactive([]);
	//标题的标签
	const titleTags = reactive([]);
	//内容的标签
	const contentTags = reactive([]);
	//标题输入框
	const inputTitleText = ref("");
	//内容输入框
	const inputContentText = ref("");
	const projectList = reactive([]);
	const projectShow = ref(false);
	const ywShow = ref(false);
	//默认勾中项目
	const updownClickData = ref(3);
	const displayAddrClickData = ref()
	const projectClickData = ref()

	//弹出框
	function toggle(type, index, item, opentype) {
		selectDayList.splice(0, selectDayList.length)
		selectTimeList.splice(0, selectTimeList.length)
		todayUseTime.splice(0, todayUseTime.length);
		ywShow.value = false;
		projectShow.value = false;
		if ('new' == opentype) {
			openTitle.value = "个人计划新增"
			isMulti.value = false;
			isEdit.value = false;
		} else if ('edit' == opentype) {
			openTitle.value = "个人计划编辑"
			editobj = getItem(index, item);
			typeDefault.value = editobj.type;
			inputTitleText.value = editobj.title;
			inputContentText.value = editobj.content;
			clickDate.value = editobj.workDate;
			isEdit.value = true;
			if (1 == typeDefault.value) {
				projectShow.value = true;
			}
			if (5 == typeDefault.value) {
				ywShow.value = true;
			}
		} else if ('multiedit' == opentype) {
			isMulti.value = true;
			openTitle.value = "批量计划编辑【" + clickItems.length + "】个"
			typeDefault.value = 0;
			inputTitleText.value = "";
			inputContentText.value = "";
			isEdit.value = true;
			isMulti.value = true;
		}
		popup.value.open(type)
		if (opentype == 'new') {
			clickDate.value = tableData[index].workDate;
			let d = {
				workDate: clickDate.value
			}
			if (props.senditem != null) {
				d.userId = props.senditem.id;
			}
			//已经使用的时间
			http.post("/personalPlan/getUsedTime", d).then((res) => {
				if (res && res.data && res.data.code == 1) {
					res.data.data.forEach((item) => {
						todayUseTime.push(item);
					});
					todayUseTime.unshift(item.startTime + "-" + item.endTime);
				}
			}).catch((re) => {
				console.log(re);
			});
		}
		let dd = {
			workDate: clickDate.value
		}
		if (props.senditem != null) {
			dd.userId = props.senditem.id;
		}
		//项目计划列表
		http.get("/projectPlan/getProjectPlansByUserId", dd).then((res) => {
			if (res && res.data && res.data.code == 1) {
				res.data.data.forEach((item) => {
					projectList.push(item);
				});
			}
		}).catch((re) => {
			console.log(re);
		});
		//标题标签
		http.post("/tag/query", {
			type: 'personal-title'
		}).then((res) => {
			if (res && res.data && res.data.code == 1) {
				titleTags.splice(0, titleTags.length)
				res.data.data.forEach((item) => {
					titleTags.push(item);
				});
			}
		}).catch((re) => {
			console.log(re);
		});
		//内容标签
		http.post("/tag/query", {
			type: 'personal-content'
		}).then((res) => {
			if (res && res.data && res.data.code == 1) {
				contentTags.splice(0, titleTags.length)
				res.data.data.forEach((item) => {
					contentTags.push(item);
				});
			}
		}).catch((re) => {
			console.log(re);
		});
		//上下游
		http.post("/typeDic/getUpDown").then((res) => {
			if (res && res.data && res.data.code == 1) {
				updownList.splice(0, updownList.length)
				res.data.data.forEach((item) => {
					updownList.push(item);
				});
				updownList.unshift({
					id: 3,
					label: "全部",
					value: 3
				})
			}
		}).catch((re) => {
			console.log(re);
		});
		//地点List
		http.post("/typeDic/table3", {
			keyWord: "person_plan_ywtype",
			page: 1,
			size: 10000
		}).then((res) => {
			if (res && res.data && res.data.code == 1) {
				addrList.splice(0, addrList.length);
				dispAddrList.splice(0, dispAddrList.length);
				res.data.rows.forEach((item) => {
					addrList.push(item);
					dispAddrList.push(item);
				});
			}
		}).catch((re) => {
			console.log(re);
		});
	}
	//翻页
	// function doChangePage(e) {
	// 	params.value.page = e.current;
	// 	loading.value = true;
	// 	http.post("/projectPlan/getRecentCompletePlan", params.value).then((res) => {
	// 		if (res && res.data && res.data.code == 1) {
	// 			tableData.splice(0,tableData.length)
	// 			tableData.push(...res.data.data);
	// 			total.value = res.data.total;
	// 			loading.value = false;
	// 		}
	// 	}).catch((re) => {
	// 		loading.value = false;
	// 	});
	// }
	//index反回周几
	function getChineseFromIndex(index) {
		switch (index) {
			case 0:
				return '周一';
			case 1:
				return '周二';
			case 2:
				return '周三';
			case 3:
				return '周四';
			case 4:
				return '周五';
			case 5:
				return '周六';
		}
		return ""
	}
	//处理权重
	function getPlanWeight(element) {
		//获取计划权重
		if (element.userId != element.creatorId) {
			//领导下发任务
			return 50;
		}
		if (element.type == 1) {
			//1=项目事务
			return 40;
		}
		if (element.type == 3) {
			//3=额外事务
			return 30;
		}
		if (element.type == 0) {
			//0=日常事务
			return 20;
		}
		if (element.type == 2) {
			//2=空闲
			return 10;
		}
		if (element.type == 4) {
			//4=请假
			return 60;
		}
		if (element.type == 5) {
			//5=业务专属
			return 70;
		}
		return null;
	}
	//处理map
	function doMap() {
		tmap.clear();
		tableData.forEach((item, index) => {
			item.personalPlanList.forEach((item2) => {
				tmap.set(index + "_" + item2.startTime + "-" + item2.endTime, item2);
			})
		})
		console.log("-----tmap----", tmap);
	}
	//打开色
	function openColorPick() {
		colorPicker.value.open();
	}
	//关闭
	function colseColorPick() {
		colorPicker.value.close();
	}

	function iconClick(type) {

	}
	//选择器定了确认
	function confirmColor(e) {
		clickColor.value = e.hex;
		console.log(e, clickColor)
	}
	//计划保存
	function planSave() {
		if (inputTitleText.value == "") {
			myuToast.value.show({
				"type": "error",
				message: "标题不能为空！"
			})
			return;
		}
		if (inputContentText.value == "") {
			myuToast.value.show({
				"type": "error",
				message: "内容不能为空！"
			})
			return;
		}
		let d = {};
		if (!isEdit.value) {
			if (props.senditem != null) {
				d.userId = props.senditem.id;
			}
			d.type = typeDefault.value;
			d.title = inputTitleText.value;
			d.content = inputContentText.value;
			todayUseTime.forEach((item) => {
				selectTimeList.push(item);
			})
			selectDayList.push(clickDate.value);
			d.selectTimeList = selectTimeList.join(",");
			d.selectDayList = selectDayList.join(",");
			//新增
			http.post("/personalPlan/edit", d).then((res) => {
				if (res && res.data && res.data.code == 1) {
					myuToast.value.show({
						type: "success",
						message: "保存成功"
					});
					clickItems.splice(0, clickItems.length)
					popup.value.close();
					findData();
				} else {
					myuToast.value.show({
						type: "error",
						message: res.data.msg
					})
				}
			}).catch((re) => {
				console.log(re)
			});
		} else {
			//单个编辑
			if (clickItems.length == 1 || clickItems.length == 0) {
				d = editobj;
				d.type = typeDefault.value;
				d.title = inputTitleText.value;
				d.content = inputContentText.value;
				delete d.creator; //删除多余数据项目
				http.post("/personalPlan/edit", d).then((res) => {
					if (res && res.data && res.data.code == 1) {
						myuToast.value.show({
							type: "success",
							message: "保存成功"
						});
						clickItems.splice(0, clickItems.length)
						popup.value.close();
						findData();
					} else {
						myuToast.value.show({
							type: "error",
							message: res.data.msg
						})
					}
				}).catch((re) => {
					console.log(re)
				});
			} else { //多个
				d.type = typeDefault.value;
				d.title = inputTitleText.value;
				d.content = inputContentText.value;
				let ids = [];
				clickItems.forEach((n) => {
					let v = n.split("_");
					let vv = v[1].split("-");
					let i = {
						startTime: vv[0],
						endTime: vv[1]
					}
					let id = getItem(v[0], i);
					ids.push(id.id);
				});
				d.planIds = ids.join(",");
				http.post("/personalPlan/multiEdit", d).then((res) => {
					if (res && res.data && res.data.code == 1) {
						myuToast.value.show({
							type: "success",
							message: "保存成功"
						});
						clickItems.splice(0, clickItems.length)
						popup.value.close();
						findData();
					} else {
						myuToast.value.show({
							type: "error",
							message: res.data.msg
						})
					}
				}).catch((re) => {
					console.log(re)
				});
			}
		}
	}
	//计划取消
	function planClose() {
		popup.value.close();
	}
	//留言面板
	function doLeaveWords() {
		uni.navigateTo({
			url: '/pages/components/leave-words/leave-words'
		})
	}
	//提醒设置
	function alertSet() {
		uni.navigateTo({
			url: '/pages/personal-plan/components/alert-setting/alert-setting'
		})
	}
	//显示统计图
	function showChart() {
		chartShow.value = !chartShow.value;
	}
	//找数据
	function findData() {
		loading.value = true;
		if (props.senditem != null) {
			params.value.userId = props.senditem.id;
		}
		http.post("/personalPlan/getPersonalPlanByWeek", params.value).then((res) => {
			if (res && res.data && res.data.code == 1) {
				tableData.splice(0, tableData.length)
				tableData.push(...res.data.rows);
				doMap();
			}
			loading.value = false;
		}).catch((re) => {
			loading.value = false;
		});
	}
	//转换周
	function changeWeek(type) {
		//改变日期列表
		http.post("/personalPlan/changeWeek", {
			name: type
		}).then((res) => {
			if (res && res.data && res.data.code == 1) {
				params.value.workDate = res.data.data;
				findData();
			}
		}).catch((re) => {
			console.log(re);
		});

	}

	function confirmDate(e) {
		params.value.workDate = formatDate(new Date(e.value), "yyyy-MM-dd");
		console.log(params.value, e);
		showCalendar.value = false;
		findData()
	}

	function cancelDate() {
		showCalendar.value = false;
	}
	//得到cell的值
	function getItem(index, item) {
		return tmap.get(index + "_" + item.startTime + "-" + item.endTime)
	}
	//根据item的type值得到class
	function getItemForClass(index, item, type) {
		let nn = tmap.get(index + "_" + item.startTime + "-" + item.endTime);
		if (nn && nn.creatorId == "2" && pinia.userId != "2") {
			return "abj"
		}
		if (type != "c") {
			if (nn) {
				return "bj" + nn.type;
			} else {
				return "bj";
			}
		} else {
			if (nn) {
				return "nbj" + nn.type;
			} else {
				return "nbj";
			}
		}
	}
	//多选框变化
	function checkboxChange(e) {
		clickItems.splice(0, clickItems.length);
		e.detail.value.forEach((item) => {
			clickItems.push(item);
		})
		if (clickItems.length == 1) {
			fab.content = fab.contentsingle
			setTimeout(() => {
				myfab.value.open();
			}, 1000)
		}
		if (clickItems.length > 1) {
			fab.content = fab.contentmult;
		}
		console.log(e, clickItems)
	}
	//得到选择框名
	function getCheckBoxName(index, item) {
		return index + "_" + item.startTime + "-" + item.endTime;
	}
	//得到按钮的类型
	function getButtonType(t, item, t2) {
		if (t.includes(item.startTime + '-' + item.endTime) && t[0] == (item.startTime + '-' + item.endTime)) {
			return "primary";
		} else if (t.includes(item.startTime + '-' + item.endTime)) {
			return "warn"
		} else if (t2.includes(item.startTime + '-' + item.endTime)) {
			return "primary"
		} else {
			return "default"
		}
	}
	//类型radio点击
	function radioTypeChange(e) {
		projectShow.value = false;
		ywShow.value = false;
		typeDefault.value = e;
		if (e == 1) {
			projectShow.value = true;
		}
		if (e == 5) {
			ywShow.value = true;
		}
	}
	//类型radio project点击
	function radioTypeChangeProject(e) {
		inputTitleText.value = e;
	}
	//类型radio updown点击
	function radioTypeChangeUpdown(e) {
		dispAddrList.splice(0, dispAddrList.length);
		if (e == 3) {
			addrList.forEach((item) => {
				dispAddrList.push(item);
			});
		} else {
			let t = addrList.filter(item => item.updown == e)
			t.forEach((item) => {
				dispAddrList.push(item);
			})
		}
	}
	//类型radio yw点击
	function radioTypeChangeYwlist(e) {
		inputTitleText.value = e.split("_")[1];
	}
	//点击删除标签
	function deleteTag(item, deleteType) {
		console.log(deleteType)
		utils.showConfirm("确认要删除吗?", function() {
			http.post("/tag/delete", {
				id: item.id
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					http.post("/tag/query", {
						type: deleteType
					}).then((res) => {
						if (res && res.data && res.data.code == 1) {
							if ("personal-title" == deleteType) {
								titleTags.splice(0, titleTags.length);
							} else if ("personal-content" == deleteType) {
								contentTags.splice(0, contentTags.length);
							}
							res.data.data.forEach((item) => {
								if ("personal-title" == deleteType) {
									titleTags.push(item);
								} else if ("personal-content" == deleteType) {
									contentTags.push(item);
								}
							});
						} else {
							myuToast.value.show({
								type: "error",
								message: res.data.msg
							})
						}
					}).catch((re) => {
						console.log(re);
					});
				}
			}).catch((re) => {
				console.log(re);
			});
		})

	}
	//点击加入标签
	function addTag(type) {
		console.log(type)
		let text = ""
		if (type == "personal-title") {
			text = inputTitleText.value;
		} else if (type == "personal-content") {
			text = inputContentText.value;
		}
		if (text == "" || !text) {
			myuToast.value.show({
				type: "error",
				message: "标签名不能为空"
			});
			return;
		}
		http.post("/tag/add", {
			type: type,
			name: text,
			color: clickColor.value
		}).then((res) => {
			if (res && res.data && res.data.code == 1) {
				http.post("/tag/query", {
					type: type
				}).then((res) => {
					if (res && res.data && res.data.code == 1) {
						if ("personal-title" == type) {
							titleTags.splice(0, titleTags.length);
						} else if ("personal-content" == type) {
							contentTags.splice(0, contentTags.length);
						}
						res.data.data.forEach((item) => {
							if ("personal-title" == type) {
								titleTags.push(item);
							} else if ("personal-content" == type) {
								contentTags.push(item);
							}
						});
					} else {
						myuToast.value.show({
							type: "error",
							message: res.data.msg
						})
					}
				}).catch((re) => {
					console.log(re);
				});
			} else {
				console.log(myuToast.value)
				myuToast.value.show({
					type: 'error',
					message: res.data.msg
				})
			}
		}).catch((re) => {
			console.log(re);
		});
	}
	//日期点击
	function dayClick(item) {
		if (selectDayList.includes(item.workDate)) {
			var index = selectDayList.indexOf(item.workDate);
			selectDayList.splice(index, 1);
		} else {
			selectDayList.push(item.workDate);
		}
	}
	//日期点击
	function timeClick(item) {
		if (selectTimeList.includes(item.startTime + "-" + item.endTime)) {
			var index = selectTimeList.indexOf(item.startTime + "-" + item.endTime);
			selectTimeList.splice(index, 1);
		} else {
			selectTimeList.push(item.startTime + "-" + item.endTime);
		}
		console.log(item)
	}
	//业务输入框
	function searchYw() {
		dispAddrList.splice(0, dispAddrList.length);
		if (inputSearchYw.value == "") {
			addrList.forEach((item) => {
				dispAddrList.push(item);
			})
		} else {
			addrList.forEach((item) => {
				if (item.name.indexOf(inputSearchYw.value) != -1) {
					dispAddrList.push(item);
				}
			})
		}
	}

	function switchChange() {
		console.log(ywShow.value)
		ywShow.value = !ywShow.value;
	}
	//点击标签
	function clickTag(t, type) {
		if (type == 'title') {
			inputTitleText.value = t;
		} else if (type == 'content') {
			inputContentText.value = t;
		}
	}

	function triggerfab(e) {
		console.log(e)
		fab.content[e.index].active = !e.item.active
		let text = fab.content[e.index].text;
		if (text == '完成' || text == '批量完成') {
			let ids = [];
			clickItems.forEach((n) => {
				let v = n.split("_");
				let vv = v[1].split("-");
				let i = {
					startTime: vv[0],
					endTime: vv[1]
				}
				let id = getItem(v[0], i);
				ids.push(id.id);
			});
			http.post("/personalPlan/completeByPlanIds", {
				planIds: ids.join(",")
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					clickItems.splice(0, clickItems.length)
					findData()
				} else {
					myuToast.value.show({
						type: "error",
						message: res.data.msg
					})
				}
			}).catch((re) => {
				console.log(re);
			});
		} else if (text == '取消完成' || text == '批量取消') {
			let ids = [];
			clickItems.forEach((n) => {
				let v = n.split("_");
				let vv = v[1].split("-");
				let i = {
					startTime: vv[0],
					endTime: vv[1]
				}
				let id = getItem(v[0], i);
				ids.push(id.id);
			});
			http.post("/personalPlan/uncompleteByPlanIds", {
				planIds: ids.join(",")
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					clickItems.splice(0, clickItems.length)
					findData()
				} else {
					myuToast.value.show({
						type: "error",
						message: res.data.msg
					})
				}
			}).catch((re) => {
				console.log(re);
			});
		} else if (text == '删除' || text == '批量删除') {
			let ids = [];
			clickItems.forEach((n) => {
				let v = n.split("_");
				let vv = v[1].split("-");
				let i = {
					startTime: vv[0],
					endTime: vv[1]
				}
				let id = getItem(v[0], i);
				ids.push(id.id);
			});
			http.post("/personalPlan/deleByPlanIds", {
				planIds: ids.join(",")
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					clickItems.splice(0, clickItems.length)
					findData()
				} else {
					myuToast.value.show({
						type: "error",
						message: res.data.msg
					})
				}
			}).catch((re) => {
				console.log(re);
			});
		} else if (text == '批量修改') {
			toggle('bottom', null, null, 'multiedit');
		} else if (text == '全天删除') {
			let n = clickItems[0];
			let v = n.split("_");
			let vv = v[1].split("-");
			let i = {
				startTime: vv[0],
				endTime: vv[1]
			}
			let itemm = getItem(v[0], i);
			http.post("/personalPlan/deleAllDay", {
				workDate: itemm.workDate
			}).then((res) => {
				if (res && res.data && res.data.code == 1) {
					clickItems.splice(0, clickItems.length)
					findData()
				} else {
					myuToast.value.show({
						type: "error",
						message: res.data.msg
					})
				}
			}).catch((re) => {
				console.log(re);
			});
		}
	}

	function goReport(type, index) {
		let d = {}
		d.id = pinia.userId;
		d.type = type;
		if (type == 0) {
			d.startDate = tableData[index].workDate
		} else {
			d.startDate = tableData[1].workDate
		}
		http.post("/zrReport/getFormPlan", d).then((res) => {
			if (res && res.data && res.data.code == 1) {
				let url = "/pages/personal-plan/show-report?title=" + res.data.data.title + "&content=" + res.data
					.data.content + "&type=" + res.data.data.type;
				uni.navigateTo({
					url: url
				})
			} else {
				myuToast.value.show({
					type: "error",
					message: res.data.msg
				})
			}
		}).catch((re) => {
			console.log(re);
		});
	}

	function showFirstColF() {
		showFirstCol.value = !showFirstCol.value;
	}
</script>
<style scoped>
	@import '@/static/css/item.css';
</style>